package com.boolib.commons.util;

import com.google.common.base.Optional;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class CacheUtil  {

    private CacheUtil(){

    }

    private static  CacheUtil cacheUtil ;

    static {
        cacheUtil = new CacheUtil();
    }
    public static CacheUtil getInstance(){

        return cacheUtil;
    }



    LoadingCache<String ,Integer> cache = CacheBuilder.newBuilder().initialCapacity(200)  .maximumSize(1000).expireAfterAccess(15L,TimeUnit.MINUTES)
            .build(new CacheLoader<String, Integer>() {

                @Override
                public Integer load(String key) throws Exception {
                    return -1;
                }
            });









    public Integer getValue(String key) throws ExecutionException {
       return   cache.get(key) ;
    }


    public void put(String key, Integer value) {
        cache.put(key,value);

    }
}
